import { createApp } from 'vue'
import pinia, { store } from '@/stores'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue' // global css
import App from './App.vue'
import router from './router'
import * as echarts from 'echarts'
import { isNull, parseTime, dictLabel } from './utils'
import formValidate from './utils/formValidate'
import 'virtual:svg-icons-register'
import '@/styles/index.scss'
import VueBMap, { initBMapApiLoader } from 'vue-bmap-gl'
import 'vue-bmap-gl/dist/style.css'
import { permissionDirective } from '@/directive/permission/permission'
import NProgress from 'nprogress'
import AMapLoader from '@amap/amap-jsapi-loader'
import 'nprogress/nprogress.css'
import { mixin } from '@/mixin'
const app = createApp(App)
app.config.globalProperties.$echarts = echarts
app.use(pinia)
app.use(router)
app.use(ElementPlus)
app.mixin(mixin)
initBMapApiLoader({
  ak: '6C45Mk02tovos4GSlTqp0Vptp8MZjQv7',
  plugins: 'Lushu,TrackAnimation'
})
app.use(VueBMap)

// 初始化图标
app.config.globalProperties.$icons = []
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.config.globalProperties.$icons.push(key)
  app.component(key, component)
}

app.directive('permission', permissionDirective)

// 定义字典全局方法
app.config.globalProperties.dictList = function (code) {
  return store.dictStore.dicts[code]
}
app.config.globalProperties.dictLabel = dictLabel

// 解析时间格式
app.config.globalProperties.parseTime = parseTime
// 表单校验
app.config.globalProperties.formValidate = formValidate
// pinia
app.config.globalProperties.$store = store
// 判空函数
app.config.globalProperties.isNull = isNull
if (localStorage.getItem('themeColor')) {
  document.documentElement.style.setProperty('--el-color-primary', `rgba(${localStorage.getItem('themeColor')})`)
  // document.documentElement.style.setProperty('--ep-color-primary3', `rgba(${localStorage.getItem('themeColor')})`)
  document.documentElement.style.setProperty('--ep-color-primary-3-op', `rgba(${localStorage.getItem('themeColor')}, 0.1)`)
  document.documentElement.style.setProperty('--el-color-primary-light-9', `rgba(${localStorage.getItem('themeColor')}, 0.05)`)
} else {
  document.documentElement.style.setProperty('--el-color-primary-light-9', `rgba(23, 98, 242, 0.05)`)
}

AMapLoader.load({
  key: 'c823368e1e9c1f3691940e691a274ce2', // 此处填入我们注册账号后获取的Key
  version: '2.0', // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
  plugins: ['AMap.ToolBar', 'AMap.ControlBar'] // 需要使用的的插件列表，如比例尺'AMap.Scale'等
}).then((AMap) => {
  app.config.globalProperties.$AMap = AMap
}).catch(e => {
  console.log(e)
})
// 正式环境清除所有console.log
if (process.env.NODE_ENV === 'production') {
  if (window) {
    window.console.log = function () {}
  }
}
NProgress.configure({ showSpinner: false })
app.mount('#app')
